<?
require_once('./lib/Config.php');
require_once('./lib/DB.gear.php');
require_once('./lib/lib.gear.php');
require_once('./lib/lib.garden.php');
require_once('./lib/oauth.class.php');
require_once('./lib/people.class.php');
require_once('./lib/signup.class.php');

if(isset($_POST['g_key_din39s03j23ogn']) && $_POST['g_key_din39s03j23ogn'] == G_KEY)
{
    $user_id       = $_POST['user_id'];
    $pod_id        = $_POST['pod_id'];
	$type          = $_POST['type'];


	switch($type)
	{
		case 'pod_list':
		    $db = new DB_GEAR();

		    //set query
		    $aQuery['Type']   = 'direct';
		    $aQuery['Query']  = 'select pod.* from garden_pod_members_tbl as member left join garden_pod_tbl as pod on member.pod_id = pod.pod_id where member.user_id = '.$user_id;

		    //set query
		    $db->set_query($aQuery);
		    //echo $db->get_query();
		    //send query
		    $result = $db->send_query(1);

			if(mysql_num_rows($result)){
				while($rec = mysql_fetch_array($result,MYSQL_ASSOC))
				{
					$data[] = $rec;
				}
			}
			else
			{
			    $data = array(
			                   'status'  => '0',
			                  );
			}

		    $json_data = json_encode($data);
		    echo $json_data;
		break;

		case 'pod_member':
		    $db = new DB_GEAR();

		    //set query
		    $aQuery['Type']   = 'direct';
		    $aQuery['Query']  = 'select user.* from garden_pod_members_tbl as member left join garden_user_tbl as user on member.user_id = user.user_id where member.pod_id = '.$pod_id;

		    //set query
		    $db->set_query($aQuery);
		    //echo $db->get_query();
		    //send query

		    $result = $db->send_query(1);
		    
			if(mysql_num_rows($result)){
				while($rec = mysql_fetch_array($result,MYSQL_ASSOC))
				{
					$data[] = $rec;
				}
			}
			else
			{
			    $data = array(
			                   'status'  => '0',
			                  );
			}
		    $json_data = json_encode($data);
		    echo $json_data;
		break;

		case 'pod_contents':
		    $db = new DB_GEAR();

		    //set query
		    $aQuery['Type']   = 'direct';
		    $aQuery['Query']  = 'select contents.*, user.user_name, user.profile_image from garden_contents_tbl as contents left join garden_user_tbl as user on contents.user_id = user.user_id where contents.pod_id = '.$pod_id.' order by time_stamp desc';

		    //set query
		    $db->set_query($aQuery);
		    //echo $db->get_query();
		    //send query
		    $result = $db->send_query(1, 1, 1);

			if(mysql_num_rows($result)){
				while($rec = mysql_fetch_array($result,MYSQL_ASSOC))
				{
					$data[] = $rec;
				}
			}
			else
			{
			    $data = array(
			                   'status'  => '0',
			                  );
			}

		    $json_data = json_encode($data);
		    echo $json_data;
		break;

		case 'add_pod_member':
		    $db = new DB_GEAR();

			//set query
			$aQuery['Type']   = 'replace into';
			$aQuery['Column'] = array(
			                      'pod_id' => $pod_id,
			                      'user_id' => $user_id,
			);
			$aQuery['Table']  = 'garden_pod_members_tbl';

		    //set query
		    $db->set_query($aQuery);

		    //send query
		    $result = $db->send_query(1);

		    if($result['cnt'] == 1)
		    {
			    $data = array(
			                   'status'  => 'OK',
			                  );
		    }
		    else
		    {
			    $data = array(
			                   'status'  => 'NG',
			                  );
		    }
		    $json_data = json_encode($data);
		    echo $json_data;
		break;
	
	}

}
else
{
    echo preDump($_POST);
}

?>
